/*
 * @Author: xxch2019
 * @Date: 2020-04-28 09:43
 * @LastEditTime: 2020-04-28 09:43
 * @LastEditors: Please set LastEditors
 * @Description: 签字意见分组
 * @FilePath: src4js/mobile4mobx/odoc/stores/signGroupPage/signGroupPageStore.js
 */
import {observable, action, toJS} from 'mobx';
import { Form, ListViewPage, RouteLayout  } from 'weaver-mobile-page';
import { Tools, Toast, Bubble } from 'weaver-mobile';
import * as API from '../../apis/odocRequest/index';
// import jQuery from 'jquery';
const getLabel = Tools.getLabel;
const jQuery = window.jQuery;
export default class SignGroupPageStore {

    /**
     * 通用方法
     * @param map
     */

    @action
    setProperty = (map)=>{
        for(let i in map){
            this[i] = map[i];
        }
    }

    @observable workflowid="";//176
    @observable requestid="";//63221
    @observable groupLists = [];
    @observable counts = 20;
    @observable lastTabid = "";
    @observable tabType = 1;
    @observable tabid = "";
    @observable pageLoading = false;
    @observable logParams = {};
    @observable tabPage = 0;
    @observable tabs ={};

    @action
    initLogParams = (commonParam)=>{
        let {authStr,authSignatureStr,signatureAttributesStr,signatureSecretKey,f_weaver_belongto_userid} = commonParam;
        this.logParams = {authStr,authSignatureStr,signatureAttributesStr,signatureSecretKey,f_weaver_belongto_userid}
    }

    /**
     * 签字意见分组页面
     */
    @action("签字意见分组默认加载")
    getSignGroupPageList =()=>{
        Toast.loading('Loading...',100);
        let params = {
            workflowid :this.workflowid,
            requestid :this.requestid,
            action:"all",
            counts:this.counts,
            tabid:this.tabid,
            ...toJS(this.logParams)
        }
        API.getSignGroupPageData(params).then(data=>{
            if(data.api_status && data.api_status==true){
                let dataMap=toJS(this.tabs);
                dataMap[this.tabid] = data.groupLists;
                this.tabs = dataMap
                this.pageLoading = false;
                Toast.hide();
                this.imgForLazyLoad();
            }
        })
    }

    @action("签字意见分组加载更多")
    signGroupPageLoadMore =(groupid,mouldid,pagenumber,index)=>{
        Toast.loading('Loading...',100);
        this.pageLoading = true;
        let params = {
            mouldid,
            groupid,
            action:"more",
            workflowid :this.workflowid,
            requestid :this.requestid,
            pagenumber:parseInt(pagenumber)+1,
            counts:this.counts,
            tabid:this.tabid,
            ...toJS(this.logParams)
        }
        API.getSignGroupPageData(params).then(data=>{
            if(data.api_status && data.api_status==true){

                let groupdatas = data.groupLists[0].groupDatas;
                let tabDatas = this.tabs[this.tabid][index];
                tabDatas.groupDatas = [
                    ...tabDatas.groupDatas,
                    ...groupdatas
                ]

                tabDatas.pagenumber = parseInt(pagenumber)+1;
                tabDatas.hasmore = groupdatas.length<this.counts?"0":"1";
                this.pageLoading = false;
                Toast.hide();
                this.imgForLazyLoad();
            }
        }).catch(error=>{
            this.pageLoading = false;
        })
    }


    @action
    imgForLazyLoad=()=>{
        let i = 0;
        let timer = setInterval(function () {
            i++;
            if(window.formImgLazyLoad && jQuery('.workflow-signSetting')){
                window.formImgLazyLoad(jQuery('.workflow-signSetting'));
            }
            if(i>=4){
                clearInterval(timer);
            }
        },500)

    }

}